package ${controllerPackageName};

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.hishenframework.data.Page;
import ${entityPackageName}.${entityClassName};
import ${servicePackageName}.${serviceClassName};

@Controller("Admin${controllerClassName}")
@RequestMapping(${controllerClassName}.PATH)
public class ${controllerClassName} {

	public static final String PATH = "/admin${urlPath}";
	public static final String RELOAD = "redirect:" + PATH;
	
	@Resource
	private ${serviceClassName} ${serviceVarName};
	
	/**
	 * ${fn_label(entityClass)}
	 * @param page 分页对象
	 * @return 路径
	 */
	@RequestMapping
	public String list(Page page) {
		${serviceVarName}.list(page);
		return PATH + "/list";
	}
	
	/** 添加${fn_label(entityClass)} */
	@RequestMapping("/create")
	public void create() {}
	
	/**
	 * 保存${fn_label(entityClass)}
	 * @param ${entityVarName} ${fn_label(entityClass)}实体
	 * @return
	 */
	@RequestMapping("/save")
	public String save(${entityClassName} ${entityVarName}) {
		${serviceVarName}.save(${entityVarName});
		return RELOAD;
	}
	
	/**
	 * 编辑${fn_label(entityClass)}
	 * @param model 模型
	 * @param id 主键
	 * @return 路径
	 */
	@RequestMapping("/edit/{id}")
	public String edit(Model model, @PathVariable Integer id) {
		model.addAttribute(${serviceVarName}.get(id));
		return PATH + "/edit";
	}
	
	/**
	 * 更新${fn_label(entityClass)}
	 * @param ${entityVarName} ${fn_label(entityClass)}实体
	 * @return 路径
	 */
	@RequestMapping("/update")
	public String update(${entityClassName} ${entityVarName}) {
		${serviceVarName}.update(${entityVarName});
		return RELOAD;
	}

	/**
	 * 删除${fn_label(entityClass)}
	 * @param id 主键
	 * @return 路径
	 */	
	@RequestMapping("/delete")
	public String delete(Integer[] id) {
		${serviceVarName}.delete(id);
		return RELOAD;
	}
}
